package com.hl.controller;

import com.hl.common.constant.Constants;
import com.hl.common.controller.BaseController;
import com.hl.common.domain.AjaxResult;
import com.hl.common.page.TableDataInfo;
import com.hl.domain.Film;
import com.hl.domain.vo.FilmQueryVo;
import com.hl.service.IFilmService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 电影管理Controller
 *
 * @author Jimbo
 * @date 2025-03-13
 */
@RestController
@RequestMapping("/film")
@Api(tags = "电影接口", value = "电影的CRUD操作")
public class FilmController extends BaseController {
    @Autowired
    private IFilmService filmService;

    /**
     * 查询电影列表
     */
    @ApiOperation(value = "查询所有电影", notes = "这是查询所有员工的方法,实现分页")
    @GetMapping("/list")
    public AjaxResult list(@RequestParam(value = Constants.PAGE_NUM, required = false, defaultValue = Constants.PAGE_NUM_DEFAULT) Integer pageNum,
                           @RequestParam(value = Constants.PAGE_SIZE, required = false, defaultValue = Constants.PAGE_SIZE_DEFAULT) Integer pageSize,
                           FilmQueryVo filmQueryVo) {
        System.out.println(pageNum + " " + pageSize + " " + filmQueryVo);
        Map<String, Object> map = filmService.selectFilmList(pageNum, pageSize, filmQueryVo);
        return success(map);
    }

    /**
     * 获取电影详细信息
     */
    @ApiOperation(value = "根据id查询电影信息", notes = "根据id查询电影信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "电影编号", required = true, paramType = "path")
    })
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(filmService.selectFilmById(id));
    }

    /**
     * 新增电影
     */
    @ApiOperation(value = "新增电影信息", notes = "新增电影信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "film", value = "电影信息对象")
    })
    @PostMapping
    public AjaxResult add(@RequestBody Film film) {
        return toAjax(filmService.insertFilm(film));
    }

    /**
     * 修改电影
     */
    @ApiOperation(value = "修改电影信息", notes = "修改电影信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "film", value = "电影信息对象")
    })
    @PutMapping
    public AjaxResult edit(@RequestBody Film film) {
        return toAjax(filmService.updateFilm(film));
    }

    /**
     * 删除电影
     */
    @ApiOperation(value = "根据id删除电影信息", notes = "根据id删除电影信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "电影编号", required = true, paramType = "path")
    })
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(filmService.deleteFilmByIds(ids));
    }
}
